﻿#region Copyright(C) 2018 FI Ltd. All rights reserved.
// ==================================================================================================
// Copyright(C) 2018 FI Ltd. All rights reserved.
//
// SYSTEM NAME	    : FI.Net Application Framework
// COMPONENT ID	    : FI.Core
// COMPONENT DESC   : FI.Net Core Foundation
//
// CREATED DATE/BY  : 18 Aug 2018 / Tian Mi
//
// REVISION HISTORY :	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================
#endregion

using FI.Core.IoC;
using FI.Core.Utilities;

namespace FI.Core.Data
{
    /// <summary>
    /// The factory to create <see cref="Database"/> by the specified connection string name.
    /// </summary>
    public static class DatabaseFactories
    {
        /// <summary>
        /// Gets the database.
        /// </summary>
        /// <param name="databaseName">Name of the connection string.</param>
        /// <returns>The <see cref="Database"/>.</returns>
        public static Database GetDatabase(string databaseName)
        {
            Guard.ArgumentNotNullOrEmpty(databaseName, "databaseName");
            IServiceLocator serviceLocator = ServiceLocatorFactory.GetServiceLocator();
            IDatabaseFactory databaseFactory = serviceLocator.GetService<IDatabaseFactory>();
            return databaseFactory.GetDatabase(databaseName);
        }

        /// <summary>
        /// Gets the database.
        /// </summary>     
        /// <returns>The <see cref="Database"/>.</returns>
        public static Database GetDatabase()
        {
            IServiceLocator serviceLocator = ServiceLocatorFactory.GetServiceLocator();
            IDatabaseFactory databaseFactory = serviceLocator.GetService<IDatabaseFactory>();
            return databaseFactory.GetDatabase();
        }
    }
}
